%h3.page-title
  New Merge Request

= form_for [@project.namespace.becomes(Namespace), @project, @merge_request], url: project_new_merge_request_path(@project), method: :get, html: { class: "merge-request-form form-inline js-requires-input" } do |f|
  .hide.alert.alert-danger.mr-compare-errors
  .merge-request-branches.row
    .col-md-6
      .panel.panel-default.panel-new-merge-request
        .panel-heading
          Source branch
        .panel-body.clearfix
          .merge-request-select.dropdown
            = f.hidden_field :source_project_id
            = dropdown_toggle @merge_request.source_project_path, { toggle: "dropdown", field_name: "#{f.object_name}[source_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-source-project" }
            .dropdown-menu.dropdown-menu-selectable.dropdown-source-project
              = dropdown_title("Select source project")
              = dropdown_filter("Search projects")
              = dropdown_content do
                = render 'projects/merge_requests/dropdowns/project',
                  projects: [@merge_request.source_project],
                  selected: f.object.source_project_id
          .merge-request-select.dropdown
            = f.hidden_field :source_branch
            = dropdown_toggle f.object.source_branch || "Select source branch", { toggle: "dropdown", field_name: "#{f.object_name}[source_branch]" }, { toggle_class: "js-compare-dropdown js-source-branch git-revision-dropdown-toggle" }
            .dropdown-menu.dropdown-menu-selectable.dropdown-source-branch.git-revision-dropdown
              = dropdown_title("Select source branch")
              = dropdown_filter("Search branches")
              = dropdown_content do
                = render 'projects/merge_requests/dropdowns/branch',
                  branches: @merge_request.source_branches,
                  selected: f.object.source_branch
        .panel-footer
          .text-center= icon('spinner spin', class: 'js-source-loading')
          %ul.list-unstyled.mr_source_commit

    .col-md-6
      .panel.panel-default.panel-new-merge-request
        .panel-heading
          Target branch
        .panel-body.clearfix
          - projects = target_projects(@project)
          .merge-request-select.dropdown
            = f.hidden_field :target_project_id
            = dropdown_toggle f.object.target_project.path_with_namespace, { toggle: "dropdown", field_name: "#{f.object_name}[target_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-target-project" }
            .dropdown-menu.dropdown-menu-selectable.dropdown-target-project
              = dropdown_title("Select target project")
              = dropdown_filter("Search projects")
              = dropdown_content do
                = render 'projects/merge_requests/dropdowns/project',
                  projects: projects,
                  selected: f.object.target_project_id
          .merge-request-select.dropdown
            = f.hidden_field :target_branch
            = dropdown_toggle f.object.target_branch, { toggle: "dropdown", field_name: "#{f.object_name}[target_branch]" }, { toggle_class: "js-compare-dropdown js-target-branch git-revision-dropdown-toggle" }
            .dropdown-menu.dropdown-menu-selectable.dropdown-target-branch.js-target-branch-dropdown.git-revision-dropdown
              = dropdown_title("Select target branch")
              = dropdown_filter("Search branches")
              = dropdown_content do
                = render 'projects/merge_requests/dropdowns/branch',
                  branches: @merge_request.target_branches,
                  selected: f.object.target_branch
        .panel-footer
          .text-center= icon('spinner spin', class: "js-target-loading")
          %ul.list-unstyled.mr_target_commit

  - if @merge_request.errors.any?
    = form_errors(@merge_request)
  = f.submit 'Compare branches and continue', class: "btn btn-new mr-compare-btn"

:javascript
  new Compare({
    targetProjectUrl: "#{project_new_merge_request_update_branches_path(@source_project)}",
    sourceBranchUrl: "#{project_new_merge_request_branch_from_path(@source_project)}",
    targetBranchUrl: "#{project_new_merge_request_branch_to_path(@source_project)}"
  });
